<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Array splice</title>
</head>
<body>
  <script>
    const colors = ["red", "green", "blue"];
    // 删除
    let removed = colors.splice(0, 1);
    console.log(colors);  // ["green", "blue"]
    console.log(removed);  // ["red"]

    // 插入
    removed = colors.splice(1, 0, "yellow", "orange");
    console.log(colors);  // ["green", "yellow", "orange", "blue"]
    console.log(removed);  // 空数组

    // 替换
    removed = colors.splice(1, 1, "red", "purple");
    console.log(colors);  // ["green", "red", "purple", "orange", "blue"]
    console.log(removed);  // ["yellow"]
  </script>
</body>
</html>